<template>
  <el-dialog
    title="收货地址"
    :visible.sync="SetAccountsVisible"
    :close-on-click-modal="false"
    destroy-on-close
    @opened="toggleSelection"
    :before-close="Cancel"
  >
    <!-- {{ upoldid }} -->
    <el-table
      ref="multipleTable"
      :data="tableData"
      style="width: 100%"
      max-height="500"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="date" label="公司账套科目编号" width="180"> </el-table-column>
      <el-table-column prop="name" label="科目名称" width="180"> </el-table-column>
      <el-table-column prop="address" label="科目描述"> </el-table-column>
    </el-table>
    <div slot="footer" class="dialog-footer">
      <el-button @click="Cancel">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: ['SetAccountsVisible', 'upoldid'],
  data() {
    return {
      tableData: [
        {
          date: 'A001',
          name: '测试1',
          address: '上海市普陀区金沙江路 1518 弄'
        },
        {
          date: 'A002',
          name: '测试2',
          address: '上海市普陀区金沙江路 1517 弄'
        },
        {
          date: 'A003',
          name: '测试3',
          address: '上海市普陀区金沙江路 1519 弄'
        },
        {
          date: 'A004',
          name: '测试4',
          address: '上海市普陀区金沙江路 1516 弄'
        }
      ],
      formLabelWidth: '120px',
      ids: [],
      newids: []
    }
  },
  created() {},
  methods: {
    Cancel() {
      this.$emit('update:SetAccountsVisible', false)
    },
    submit() {
      this.$emit('transfer', this.ids)
      this.$emit('update:SetAccountsVisible', false)
    },
    handleSelectionChange(val) {
      this.ids = val.map(item => item.date)
    },

    toggleSelection() {
      this.newids = []
      this.upoldid.val98.split(',').forEach(item => {
        this.tableData.forEach(items => {
          if (item == items.date) {
            this.newids.push(items)
          }
        })
      })
      this.newids.forEach(row => {
        console.log(row)
        this.$refs.multipleTable.toggleRowSelection(row)
      })
    }
  }
}
</script>

<style scoped></style>
